#ifndef __DOUBLELINKLIST_H_
#define __DOUBLELINKLIST_H_

#include <stdbool.h>
#define ElementType void*
#define INITDLLIST(list) DLlist list; InitDLlist(&list);

//节点
struct DoubleLinkNode
{
    ElementType data;//数据域
    struct DoubleLinkNode *next;//后驱节点指针
    struct DoubleLinkNode *prev;//前驱节点指针
};
typedef struct DoubleLinkNode DLNode;

//双向链表
struct DoubleLinkList
{
    DLNode *head;//链表头节点指针
    DLNode *tail;//链表尾指针
    int len;//链表长度
};
typedef struct DoubleLinkList DLlist;

//初始化
void InitDLlist(DLlist *list);
//尾插法
void InsertDLlistTail(DLlist *list,ElementType element);
//头插法
void InsertDLlistHead(DLlist *list,ElementType element);

//按位置删除
void RemoveByIndex(DLlist *list,int index,void (*freePtr)(ElementType));
//按值删除(前一个回调是操作回调)
void RemoveByElement(DLlist *list,ElementType element,bool (*OperPtr)(ElementType,ElementType),void (*freePtr)(ElementType));

//按位置查找
ElementType* FindByIndex(DLlist *list,int index);
//按值查找
DLlist FindByElement(DLlist *list,ElementType element,bool (*OperPtr)(ElementType,ElementType));

//遍历
void TravelDLlist(DLlist *list,void(*funcPtr)(ElementType));

//排序
void DLlistSort(DLlist *list,bool (*funcPtr)(ElementType,ElementType));

//清空双向链表
void ClearDLlist(DLlist *list,void (*clearPtr)(ElementType));

#endif